//package cn.amoqi.springbootrocketmq.v1;
//
//import lombok.AllArgsConstructor;
//import lombok.Data;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.rocketmq.client.producer.SendCallback;
//import org.apache.rocketmq.client.producer.SendResult;
//import org.apache.rocketmq.spring.core.RocketMQTemplate;
//import org.apache.rocketmq.spring.support.RocketMQHeaders;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.messaging.support.MessageBuilder;
//import org.springframework.stereotype.Component;
//import org.springframework.stereotype.Controller;
//
//import javax.annotation.PostConstruct;
//import java.math.BigDecimal;
//import java.util.Collections;
//import java.util.HashMap;
//
///**
// * @Description:
// * @author: zhuiFeng
// * @date: 2021年04月15日 14:06
// */
////@Component
//@Slf4j
//public class ProducerComponent {
//
//    @Autowired
//    private RocketMQTemplate rocketMQTemplate;
//
//    @Value("${rocketmq.producer.send-message-timeout}")
//    private Integer messageTimeOut;
//
//    @PostConstruct
//    public void test(){
//        log.info("消息启动！");
//        // 如下三种方式等价,第二种加入key,第三种是另一种方式加入key
//        //rocketMQTemplate.convertAndSend("test-topic-1", "Hello, World!");
//        //rocketMQTemplate.send("test-topic-1",MessageBuilder.withPayload("Hello, World! I'm from spring message").setHeader(RocketMQHeaders.KEYS,"67").build());
//        //rocketMQTemplate.convertAndSend("test-topic-1","Hello, World!", Collections.singletonMap(RocketMQHeaders.KEYS, "pumpkin"));
//
//        // topic: ORDER，tag: paid, cacel
//        //rocketMQTemplate.convertAndSend("ORDER:paid", "Hello, World!");
//        //rocketMQTemplate.convertAndSend("ORDER:cancel", "Hello, World1!");
//        //test-topic-1 主题 | tag1 标签 | pumpkin key
//        //rocketMQTemplate.convertAndSend("test-topic-1:tag1","Hello, World!", Collections.singletonMap(RocketMQHeaders.KEYS, "pumpkin"));
//
//        //消息体为自定义对象
//        //rocketMQTemplate.convertAndSend("test-topic-2", new User("T_001", "address",1));
//
//        // 发送延迟消息,5代表1m（分钟）
//        //在start版本中 延时消息一共分为18个等级分别为：1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h
//        //rocketMQTemplate.syncSend("test-topic-1:delay",MessageBuilder.withPayload("11111").build(),messageTimeOut,5);
//
//        // 发送即发即失消息（不关心发送结果）
//        //rocketMQTemplate.sendOneWay("test-topic-1:onway", MessageBuilder.withPayload("I'm one way message").build());
//        //发送顺序消息,根据key选择队列。例如：orderId，productId
//        //rocketMQTemplate.syncSendOrderly("test-topic-1:order", "I'm order message", "1234");
//
//        // 发送异步消息
//        rocketMQTemplate.asyncSend("test-topic-1:async111777", MessageBuilder.withPayload("I'm one async messag111e").build(), new SendCallback() {
//            @Override
//            public void onSuccess(SendResult sendResult) {
//                System.out.println("发送成功");
//            }
//
//            @Override
//            public void onException(Throwable throwable) {
//                System.out.println("发送失败");
//            }
//        });
//    }
//
//    @Data
//    @AllArgsConstructor
//    class User{
//        private String name;
//        private String address;
//        private Integer age;
//    }
//}
